//
//  EJSHelpCenterDetailViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/13.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSHelpCenterDetailViewController.h"
#import "EJSArticleDetailRequest.h"

@interface EJSHelpCenterDetailViewController ()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) EJSArticleModel *articleModel;

@end

@implementation EJSHelpCenterDetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self getArticleDetail];
//    if(content && content.length > 0){
//
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getArticleDetail{
    EJSArticleDetailRequest *req = [EJSArticleDetailRequest new];
    req.articleId = self.articleId;
    FlyWeakSelf
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        weakSelf.articleModel = response.data;
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:response.message];
    }];
}

- (void)setArticleModel:(EJSArticleModel *)articleModel{
    if(_articleModel != articleModel){
        _articleModel = articleModel;
        
        NSString *imgStyle=@"<style type=\"text/css\">img{max-width:100%;height:auto;} </style>";
        NSString *textFontString = [NSString stringWithFormat:@"<style type=\"text/css\">*{font-size:%0.0fpx; color:#a} </style>",14.0];
        NSString *htmlString = [NSString stringWithFormat:@"%@%@%@", imgStyle, textFontString, _articleModel.content];
        [[HUDHelper sharedInstance] syncLoading];
        [_webView loadHTMLString:htmlString baseURL:nil];
    }
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [[HUDHelper sharedInstance] syncLoading];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [[HUDHelper sharedInstance] syncStopLoading];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [[HUDHelper sharedInstance] syncStopLoading];
}


@end
